unit U_Tools;

interface

uses
  Windows, Forms, Controls, Math, AppEvnts, F_Processing;

type
  TTools = class(TObject)
  private
    FBlockMouseInput: Boolean;
    FBlockKeyInput: Boolean;

    FProcessingCount: Integer;
    FProcessingEnabled: Boolean;

    procedure BeginWait;
    procedure EndWait;

  public
    constructor Create;
    procedure ShowProcessing(sTitle: String = ''; sContent: String = '');
    procedure HideProcessing(bForceHide: Boolean = False);
    
  end;
  
implementation

uses SysUtils;

{ TTools }

procedure TTools.BeginWait;
begin
  Screen.Cursor := crHourGlass;
  FBlockMouseInput := True;
  FBlockKeyInput := True;
end;

constructor TTools.Create;
begin
  inherited;

  FProcessingCount := 0;
  FProcessingEnabled := True;
  
end;

procedure TTools.EndWait;
begin
  FBlockMouseInput:= false;
  FBlockKeyInput:= false;
  Screen.Cursor:= crDefault;
end;

procedure TTools.HideProcessing(bForceHide: Boolean);
begin
  if bForceHide then
    FProcessingCount:= 0
  else
    FProcessingCount:= Max(FProcessingCount- 1, 0);

  if FProcessingCount = 0 then
  begin
//    if FProcessingEnabled then
    begin
      EndProcess;
      EndWait;
    end;
  end;
end;

procedure TTools.ShowProcessing(sTitle, sContent: String);
begin
  FProcessingCount:= FProcessingCount + 1;

  if FProcessingEnabled then
  begin
    BeginWait;
    BeginProcess(sTitle, sContent);
  end;
end;

end.
